import 'package:flutter/material.dart';
import 'package:flutter_learn_vi/src/bean/bean_user_account.dart';
import 'package:flutter_learn_vi/src/common/user_helper.dart';
import 'package:get/get.dart';
import 'package:get/get_state_manager/src/simple/get_state.dart';

import '../../../../bean/bean_user.dart';
import '../controller/account_center_details_controller.dart';

class AccountDetailsWidget extends StatefulWidget {
  final String tag;

  const AccountDetailsWidget({Key key, this.tag}) : super(key: key);

  @override
  State<StatefulWidget> createState() {
    return _AccountDetailsState();
  }
}

class _AccountDetailsState extends State<AccountDetailsWidget> {
  @override
  void initState() {
    super.initState();
    Get.put(AccountCenterDetailsController(), tag: widget.tag);
    Future.delayed(Duration.zero, () {
      Get.find<AccountCenterDetailsController>(tag: widget.tag)
          .requestUserAccount();
    });
  }

  @override
  Widget build(BuildContext context) {
    return Container(
      margin: EdgeInsets.only(bottom: 8, left: 12, right: 12),
      padding: EdgeInsets.only(left: 10, bottom: 10),
      decoration: BoxDecoration(
          gradient:
              LinearGradient(colors: [Color(0xFFE3F2FD), Color(0xFFBBDEFB)]),
          borderRadius: BorderRadius.all(Radius.circular(12)),
          border: Border.all(
            color: Colors.white,
          )),
      child: Container(
        child: GetBuilder(
          tag: widget.tag,
          id: "userAccount",
          builder: (AccountCenterDetailsController controller) {
            UserAccountStateBean bean = controller.userAccountStateBean;
            num total = 0;
            num yestoday = 0;
            num weekDataNum = 0;
            num monthDataNum = 0;
            String reamName = "";
            if (bean != null) {
              UserBean userBean = UserHelper.getInstance.userBean;
              if (userBean != null) {
                reamName = userBean.reamName;
              }

              UserAccountBean accountBean = bean.accountBean;
              if (accountBean != null) {
                total = accountBean.remainAmount;
              }

              UserAccountBean yestodayData = bean.yestodayData;
              if (yestodayData != null) {
                yestoday = yestodayData.orderSettleAmt;
              }

              UserAccountBean weekData = bean.weekData;
              if (weekData != null) {
                weekDataNum = weekData.orderSettleAmt;
              }

              UserAccountBean monthData = bean.monthData;
              if (monthData != null) {
                monthDataNum = monthData.orderSettleAmt;
              }
            }
            return GestureDetector(
              onTap: () {},
              child: Column(
                mainAxisSize: MainAxisSize.min,
                crossAxisAlignment: CrossAxisAlignment.start,
                children: [
                  Row(
                    children: [
                      Expanded(
                        child: Text(
                          reamName,
                          style: TextStyle(
                            fontSize: 16,
                            color: Color(0xff333333),
                            fontWeight: FontWeight.w600,
                          ),
                        ),
                      ),
                      Container(
                        width: 120,
                        padding: EdgeInsets.only(top: 8, bottom: 6, right: 12),
                        decoration: BoxDecoration(
                            color: Color(0xFF0D47A1),
                            borderRadius: BorderRadius.only(
                                bottomLeft: Radius.circular(44),
                                topRight: Radius.circular(12),
                                bottomRight: Radius.circular(4))),
                        child: Column(
                          crossAxisAlignment: CrossAxisAlignment.end,
                          mainAxisSize: MainAxisSize.min,
                          children: [
                            Text(
                              "  $total",
                              style: TextStyle(
                                  fontSize: 14, color: Color(0xffffffff)),
                            ),
                            Text(
                              "我的积分",
                              style:
                                  TextStyle(fontSize: 12, color: Colors.white),
                            )
                          ],
                        ),
                      )
                    ],
                  ),
                  SizedBox(height: 10),
                  Text(
                    "日积分  $yestoday",
                    style: TextStyle(
                        fontSize: 14,
                        color: Color(0xff333333),
                        fontWeight: FontWeight.w500),
                  ),
                  SizedBox(height: 5),
                  Row(
                    children: [
                      Expanded(
                        child: Text(
                          "周积分 $weekDataNum",
                          style: TextStyle(
                              fontSize: 14,
                              color: Color(0xff333333),
                              fontWeight: FontWeight.w500),
                        ),
                      ),
                      Text(
                        "(每周一显示的是上周的总积分)",
                        style: TextStyle(
                            fontSize: 12,
                            color: Color(0xff333333),
                            fontWeight: FontWeight.w500),
                      ),
                      SizedBox(width: 12),
                    ],
                  ),
                  SizedBox(height: 5),
                  Row(
                    children: [
                      Expanded(
                        child: Text(
                          "月积分 $monthDataNum",
                          style: TextStyle(
                            fontSize: 14,
                            color: Color(0xff333333),
                          ),
                        ),
                      ),
                      Text(
                        "(每月1日显示的是上月的总积分)",
                        style: TextStyle(
                            fontSize: 12,
                            color: Color(0xff333333),
                            fontWeight: FontWeight.w500),
                      ),
                      SizedBox(width: 12),
                    ],
                  ),
                ],
              ),
            );
          },
        ),
      ),
    );
  }
}
